package com.authine.cloudpivot.ext.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author: liwei
 * @DateTime: 2021/8/27
 * @Description: TODO
 */
@Data
@Schema(description = "OrderTraceVO")
@ApiModel("订单物流信息")
public class OrderTraceVO {

    @Schema(description = "订单物流跟踪表ID")
    private String id;
    @Schema(description = "客户订单商品ID")
    private String orderGoodsId;
    //运单号
    @Schema(description = "运单号")
    private String waybill;
    @Schema(description = "物流，自送：物流名称为自送")
    private String logistics;
    @Schema(description = "发货数量")
    private BigDecimal num;
    @Schema(description = "发货时间")
    private Date time;
    @Schema(description = "商品名称")
    private String name;
    @Schema(description = "物料编号")
    private String sku;
    @Schema(description = "公司")
    private String company;
    @Schema(description = "含税单价")
    private BigDecimal price;
    @Schema(description = "商品含税")
    private BigDecimal amount;


    public static List<OrderTraceVO> transferToOrderTraceVOList(List<Map<String, Object>> mapList) {
        if (CollectionUtils.isEmpty(mapList)){
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        List<OrderTraceVO> orderTraceVOList = new ArrayList<>();
        mapList.stream().forEach(e->{
            OrderTraceVO orderTraceVO = new OrderTraceVO();
            orderTraceVO.setId(String.valueOf(e.get("id")));
            orderTraceVO.setOrderGoodsId(String.valueOf(e.get("order_customer_goods_id")));
            orderTraceVO.setWaybill(String.valueOf(e.get("waybill")));
            orderTraceVO.setLogistics(String.valueOf(e.get("logistics")));
            orderTraceVO.setNum(new BigDecimal(String.valueOf(e.get("quantity"))));
            try {

                orderTraceVO.setTime(formatter.parse(String.valueOf(e.get("createdTime"))));

            } catch (ParseException parseException) {
                parseException.printStackTrace();
            }
            orderTraceVO.setName(String.valueOf(e.get("name")));
            orderTraceVO.setSku(String.valueOf(e.get("sku")));
            orderTraceVO.setCompany(String.valueOf(e.get("createdTime")));
            orderTraceVO.setPrice(new BigDecimal(String.valueOf(e.get("createdTime"))));
            orderTraceVO.setAmount(new BigDecimal(String.valueOf(e.get("createdTime"))));
            orderTraceVOList.add(orderTraceVO);

        });
        return orderTraceVOList;
    }
}
